package org.sninwo.lnbook.uitls;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.sninwo.lnbook.book.entity.User;

/**
 * 针对request和response的一些快捷方法
 * @author LinZongxue
 *
 */
public class WebUtils {
	private static final String LOGIN_INFO_NAME = "LOGIN_INFO";
	
	public static void setLoginInfo(User user){
		getSession().setAttribute(LOGIN_INFO_NAME, user);
	}
	
	public static User getLoginInfo(){
		return (User)getSession().getAttribute(LOGIN_INFO_NAME);
	}
	
	public static HttpServletRequest getReqeust(){
		return ServletActionContext.getRequest();
	}
	
	public static HttpServletResponse getResponse(){
		return ServletActionContext.getResponse();
	}
	
	public static HttpSession getSession(){
		return getReqeust().getSession();
	}
	
	public static String getReqParam(String name){
		return getReqeust().getParameter(name);
	}
	
	public static Object getReqAttr(String name){
		return getReqeust().getAttribute(name);
	}
	
	public static void setReqAttr(String name, Object value){
		getReqeust().setAttribute(name, value);
	}
	
	public static String getRealPath(String path){
		return getReqeust().getSession().getServletContext().getRealPath(path);
	}
}
